<template>
    <div>
        <template>
         <div class="align-right">
                <el-form :inline="true" :model="listQuery">
                    <div class="pull-right">
                        <el-form-item>
                            <el-input placeholder="请输入用户名" clearable v-model.trim="listQuery.loginId"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="handleSearch" icon="el-icon-search" >搜索</el-button>
                        </el-form-item>
                    </div>
                </el-form>
            </div>
            <el-table
            class="mb20"
            ref="LogTable"
            :data="tableDataLog"
            row-key="id"
            border
            highlight-current-row>
                <el-table-column align="center" label="序号" width ="100" >
                    <template slot-scope="scope">
                        <span >{{ scope.$index+1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="用户名">
                    <template slot-scope="scope">
                        <span >{{ scope.row.userId }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="登录IP">
                    <template slot-scope="scope">
                        <span >{{ scope.row.loginIp }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="登录时间">
                    <template slot-scope="scope">
                        <span >{{ scope.row.loginDt }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="登出时间">
                    <template slot-scope="scope">
                        <span >{{ scope.row.logoutDt }}</span>
                    </template>
                </el-table-column>
            </el-table>
             <el-col :span="24" class="pagination-warp" v-if="tableDataLog.length>0">
                <div class="text-center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="listQuery.currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="listQuery.size"
                        layout="total, sizes, prev, pager, next ,jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </el-col>
        </template>
    </div>
</template>
<script>
import { getList } from '@/api/sys/log'
export default {
    data() {
        return {
            tableDataLog: [],
            total: null,
            listQuery: {
                currentPage: 1,
                size: 10,
                loginId: undefined
            }
        }
    },
    created() {
        this.getList()
    },
    methods:{
        getList(){
            const params = this.listQuery
            getList(params).then((response) => {
                if (response.code === 0) {
                    this.tableDataLog = response.data.records
                    this.total = response.data.total
                }
            })
        },
        handleSearch(){
            this.listQuery.currentPage = 1
            this.getList()
        },
        handleSizeChange(val) {
            this.listQuery.currentPage = 1
            this.listQuery.size = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.listQuery.currentPage = val
            this.getList()
        }
    }
}
</script>
